package com.cdks.wuxiu.api.service;


import com.cdks.wuxiu.api.model.dto.MoodReplyInfoDTO;
import com.cdks.wuxiu.api.model.dto.MoodTopicInfoDTO;
import com.cdks.wuxiu.api.service.mongo.MoodTransInfoService;
import com.cdks.wuxiu.api.service.mysql.MoodReplyInfoService;
import com.cdks.wuxiu.api.service.mysql.MoodTopicInfoService;
import com.cdks.wuxiu.entity.mongodb.MoodTransInfo;
import com.cdks.wuxiu.entity.mysql.MoodReplyInfo;
import com.cdks.wuxiu.entity.mysql.MoodTopicInfo;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;


/**
 * 心情服务实现类
 */
@Slf4j
@Service
public class MoodServiceImpl implements MoodService {
    @Resource
    private MoodTopicInfoService topicInfoService;
    @Resource
    private MoodReplyInfoService replyInfoService;
    @Resource
    private MoodTransInfoService transInfoService;


    @Override
    public int saveTopic(MoodTopicInfo topicInfo) {
        boolean ret  = topicInfoService.save(topicInfo);
        if (ret)
        {
            return 0;
        }
        
        return -1;
    }

    @Override
    public int saveReply(MoodReplyInfo replyInfo) {
        boolean ret  = replyInfoService.save(replyInfo);
        if (ret)
        {
            return 0;
        }
        
        return -1;
    }

    @Override
    public int addReplyCount(long topicId) {
        int ret  = topicInfoService.addReplyCount(topicId);
        if (ret < 0)
        {
            return -1;
        }

        return 0;
    }

    @Override
    public List<MoodTopicInfoDTO> getTopicList(long userId, int type, int groupId, int page) {
        return topicInfoService.getList(userId, type, groupId, page);
    }

    @Override
    public List<MoodReplyInfoDTO> getReplyList(long userId, long topicId, long fatherId, int type, int page) {
        return replyInfoService.getList(userId, topicId, fatherId, type, page);
    }

    @Override
    public MoodTopicInfoDTO getDetailByTopicId(long topicId) {
        return topicInfoService.getDetailById(topicId);
    }

    @Override
    public MoodTopicInfo getTopicById(long topicId) {
        return topicInfoService.getById(topicId);
    }

    @Override
    public List<MoodTopicInfo> getTopicByUser(long userId, int page, int isSelf) {
        return topicInfoService.getListByUser(userId, page, isSelf);
    }

    @Override
    public MoodReplyInfo getReplyById(long replyId) {
        return replyInfoService.getById(replyId);
    }

    @Override
    public MoodTransInfo getTransByTopicId(long topicId) {
        return transInfoService.getByTopicId(topicId);
    }

    @Override
    public int setTopicById(MoodTopicInfo topicInfo) {
        boolean ret  = topicInfoService.updateById(topicInfo);
        if (ret)
        {
            return 0;
        }

        return -1;
    }

    @Override
    public int setReplyById(MoodReplyInfo replyInfo) {
        boolean ret  = replyInfoService.updateById(replyInfo);
        if (ret)
        {
            return 0;
        }

        return -1;
    }

    @Override
    public int saveTransContent(MoodTransInfo transInfo) {
        int ret  = transInfoService.saveTransContent(transInfo);
        if (ret < 0)
        {
            log.error("保存转译结果失败: ret = " + ret);

            return -1;
        }

        return 0;
    }
}
